package com.xtoad.ecms.baseinfo.model;

import com.xtoad.ecms.common.web.base.BaseModel;
import org.hibernate.annotations.Table;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import java.util.List;

/**
 * 页面
 *
 * @author xtoad
 * @date 2021/1/13
 */
@Entity
@Table(appliesTo = "web_page", comment = "页面表")
public class WebPage extends BaseModel {

    /**
     * 页面标题
     */
    @Column(nullable =false, columnDefinition = "varchar(50) comment '页面标题'")
    private String title;

    /**
     * url
     */
    @Column(nullable =false, columnDefinition = "varchar(250) comment 'url'")
    private String url;

    /**
     * 页面资源
     */
    @OneToMany(mappedBy = "page", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    private List<PageElement> elements;


    /**
     * 获取 页面标题
     */
    public String getTitle() {
        return this.title;
    }

    /**
     * 设置 页面标题
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * 获取 url
     */
    public String getUrl() {
        return this.url;
    }

    /**
     * 设置 url
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * 获取 页面资源
     */
    public List<PageElement> getElements() {
        return this.elements;
    }

    /**
     * 设置 页面资源
     */
    public void setElements(List<PageElement> elements) {
        this.elements = elements;
    }

    @Override
    public String toString() {
        return "WebPage{" +
                "title='" + title + '\'' +
                ", url='" + url + '\'' +
                ", elements=" + elements +
                "} " + super.toString();
    }
}
